package com.ruoyi.web.controller.house;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.house.domain.WebmagicBuildingDetail;
import com.ruoyi.house.service.IWebmagicBuildingDetailService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 楼宇明细Controller
 * 
 * @author ruoyi
 * @date 2023-06-09
 */
@Controller
@RequestMapping("/house/detail")
public class WebmagicBuildingDetailController extends BaseController
{
    private String prefix = "house/detail";

    @Autowired
    private IWebmagicBuildingDetailService webmagicBuildingDetailService;

    @RequiresPermissions("house:detail:view")
    @GetMapping()
    public String detail()
    {
        return prefix + "/detail";
    }

    /**
     * 查询楼宇明细列表
     */
    @RequiresPermissions("house:detail:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(WebmagicBuildingDetail webmagicBuildingDetail)
    {
        startPage();
        List<WebmagicBuildingDetail> list = webmagicBuildingDetailService.selectWebmagicBuildingDetailList(webmagicBuildingDetail);
        return getDataTable(list);
    }

    /**
     * 导出楼宇明细列表
     */
    @RequiresPermissions("house:detail:export")
    @Log(title = "楼宇明细", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(WebmagicBuildingDetail webmagicBuildingDetail)
    {
        List<WebmagicBuildingDetail> list = webmagicBuildingDetailService.selectWebmagicBuildingDetailList(webmagicBuildingDetail);
        ExcelUtil<WebmagicBuildingDetail> util = new ExcelUtil<WebmagicBuildingDetail>(WebmagicBuildingDetail.class);
        return util.exportExcel(list, "楼宇明细数据");
    }

    /**
     * 新增楼宇明细
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存楼宇明细
     */
    @RequiresPermissions("house:detail:add")
    @Log(title = "楼宇明细", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(WebmagicBuildingDetail webmagicBuildingDetail)
    {
        return toAjax(webmagicBuildingDetailService.insertWebmagicBuildingDetail(webmagicBuildingDetail));
    }

    /**
     * 修改楼宇明细
     */
    @RequiresPermissions("house:detail:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        WebmagicBuildingDetail webmagicBuildingDetail = webmagicBuildingDetailService.selectWebmagicBuildingDetailById(id);
        mmap.put("webmagicBuildingDetail", webmagicBuildingDetail);
        return prefix + "/edit";
    }

    /**
     * 修改保存楼宇明细
     */
    @RequiresPermissions("house:detail:edit")
    @Log(title = "楼宇明细", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(WebmagicBuildingDetail webmagicBuildingDetail)
    {
        return toAjax(webmagicBuildingDetailService.updateWebmagicBuildingDetail(webmagicBuildingDetail));
    }

    /**
     * 删除楼宇明细
     */
    @RequiresPermissions("house:detail:remove")
    @Log(title = "楼宇明细", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(webmagicBuildingDetailService.deleteWebmagicBuildingDetailByIds(ids));
    }
}
